'use strict';

// 登录判断
const login_fn = async (ctx, next) => {
    // 获取账号
    let username = ctx.request.body.username || '';
    // 获取密码
    let password = ctx.request.body.password || '';
    if (username === 'hyr@qq.com' && password === '123') {
        // 如果账号和密码正确,则跳转到登录成功界面
        ctx.response.redirect('/login/success');
    } else {
        // 账号或密码有误,都跳转到登录失败界面
        ctx.response.redirect('../views/404.html');
    }
}

// 登录成功
const login_success_fn = async (ctx, next) => {
    ctx.response.body = `
    <h1>登录成功,3秒后将自动跳转至主页面！</h1>
    <meta http-equiv="refresh" content="3;url=https://www.hyr6.work/">
    `;
}

// 暴露出去
module.exports = {
    '/login/login': ['post', login_fn],
    '/login/success': ['get', login_success_fn]
    // '/login/error': ['get', login_error_fn]
}